#include<bits/stdc++.h>
using namespace std;

class Per
{
	public:
		string id;
		int score;
		int final;
		int location;
		int local;
};
bool cmp1(Per e1, Per e2){ return e1.score == e2.score ? e1.id < e2.id : e1.score > e2.score; }
int main()
{
	int n, i, oneNum, j, sum = 0, tid;
	vector<Per> v[101];
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> oneNum;
		sum += oneNum; 
		v[i].resize(oneNum);
		for(j = 0; j < oneNum; j++)
		{
			cin >> v[i][j].id;
			cin >> v[i][j].score;
			v[i][j].location = i + 1;
		}
		sort(v[i].begin(), v[i].end(), cmp1);
		int last = v[i][0].score;
		v[i][0].local = 1;
		for(j = 1; j < oneNum; j++)
		{
			if(last == v[i][j].score)
			{
				v[i][j].local = v[i][j - 1].local;
			}else
				v[i][j].local = j + 1;
			last = v[i][j].score;
		}
//		cout << "------------" << endl;
//		for(j = 0; j < oneNum; j++)
//			cout << v[i][j].id << " " << v[i][j].local << endl;
	}
	for(i = 1; i < n; i++)
		for(j = 0; j < v[i].size(); j++)
		{
			v[0].push_back(v[i][j]);
		}
	sort(v[0].begin(), v[0].end(), cmp1);
	v[0][0].final = 1;
	int last = v[0][0].score;
	for(j = 1; j < sum; j++)
		{
			if(last == v[0][j].score)
			{
				v[0][j].final = v[0][j - 1].final;
			}else
				v[0][j].final = j + 1;
			last = v[0][j].score;
		}
	cout << sum << endl;
	for(j = 0; j < sum; j++)
		cout << v[0][j].id << " " << v[0][j].final << " " << v[0][j].location << " " << v[0][j].local << endl;
	return 0;
 } 
